const mysql = require("mysql2");
const config = require("./config");

const connections = mysql.createPool({
    host: config.MYSQL_HOST,
    port: config.MYSQL_PORT,
    database: config.MYSQL_DATABASE,
    user: config.MYSQL_USER,
    password: config.MYSQL_PASSWORD
});
connections.getConnection((err, connection) => {
    if (err) {
        console.error('连接异常', err);
        return;
    }
    connection.connect((err) => {
        if (err) {
            console.log('发生异常', err);
            return;
        }
        console.log("数据库连接成功");
    });
});
module.exports = connections.promise();